<?php

/**
 * 店铺消息模板模型
 *

 */
namespace app\common\model;

use think\Db;

class StoreMsg extends \think\Model
{

    /**
     * 新增店铺消息
     * @param unknown $insert
     */
    public function addStoreMsg($insert)
    {
        $time = time();
        $insert['sm_addtime'] = $time;
        $sm_id = Db::name('store_msg')->insert($insert, false, true);
        return $sm_id;
    }

    /**
     * 更新店铺消息表
     * @param unknown $condition
     * @param unknown $update
     */
    public function editStoreMsg($condition, $update)
    {
        return Db::name('store_msg')->where($condition)->update($update);
    }

    /**
     * 查看店铺消息详细
     * @param unknown $condition
     * @param string $field
     */
    public function getStoreMsgInfo($condition, $field = '*')
    {
        return Db::name('store_msg')->field($field)->where($condition)->find();
    }

    /**
     * 店铺消息列表
     * @param unknown $condition
     * @param string $field
     * @param string $page
     * @param string $order
     * @param number $limit
     */
    public function getStoreMsgList($condition, $field = '*',  $limit= 9999, $order = 'sm_id desc', $page = 1)
    {
        return Db::name('store_msg')->field($field)->where($condition)->order($order)->page($page)->limit($limit)->select();
    }

    /**
     * 计算消息数量
     * @param unknown $condition
     */
    public function getStoreMsgCount($condition)
    {
        return Db::name('store_msg')->where($condition)->count();
    }

    /**
     * 删除店铺消息
     * @param unknown $condition
     */
    public function delStoreMsg($condition)
    {
        Db::name('store_msg')->where($condition)->delete();
    }

}
